#ifndef GDATA_H
#define GDATA_H
#include "stm32f1xx_it.h"
#include "cmsis_os.h"
#include "mregs.h"

#define VAR1 1000
#define VAR2 2000
#define VAR3 3000
#define VAR4 4000
#define VARIABLE_ADDRESS 0x801fc00


typedef struct
{
    uint16_t addr_device1;
    uint16_t addr_device2;
    uint16_t addr_device3;
    uint16_t addr_device4;
    float   analog1_down;
    float   analog2_down;
    float   analog3_down;
    float   analog4_down;
    float   analog5_down;
    float   analog6_down;
    float   analog7_down;
    float   analog8_down;
    float   analog1_up;
    float   analog2_up;
    float   analog3_up;
    float   analog4_up;
    float   analog5_up;
    float   analog6_up;
    float   analog7_up;
    float   analog8_up;
    uint32_t   local_baud;
    float   analog1_adjust;
    float   analog2_adjust;
    float   analog3_adjust;
    float   analog4_adjust;
    float   analog5_adjust;
    float   analog6_adjust;
    float   analog7_adjust;
    float   analog8_adjust;
    uint16_t   firstaddr_device1;
    uint16_t   firstaddr_device2;
    uint16_t   firstaddr_device3;
    uint16_t   firstaddr_device4;
    uint32_t   device_baud;
    uint16_t   device_check;
    uint16_t   device_bytes;
    uint16_t   device_stops;
    uint16_t   addr_local;
    float      analog1;
    float      analog2;
    float      analog3;
    float      analog4;
    float      analog5;
    float      analog6;
    float      analog7;
    float      analog8;
    float      device1_total1;
    float      device1_total2;
    float      device1_current1;
    float      device1_current2;
    float      device1_press;
    float      device1_temp;
    float      device2_total1;
    float      device2_total2;
    float      device2_current1;
    float      device2_current2;
    float      device2_press;
    float      device2_temp;
    float      device3_total1;
    float      device3_total2;
    float      device3_current1;
    float      device3_current2;
    float      device3_press;
    float      device3_temp;
    float      device4_total1;
    float      device4_total2;
    float      device4_current1;
    float      device4_current2;
    float      device4_press;
    float      device4_temp;
}reg_w_t;


extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart3;
extern SPI_HandleTypeDef hspi2;
extern IWDG_HandleTypeDef hiwdg;
extern osSemaphoreId semUart3Handle;
extern osSemaphoreId semUart1Handle;
extern uint8_t u1Buff[1024];
extern uint8_t u1Len;
extern uint8_t u3Buff[1024];
extern uint8_t u3Len;
extern uint16_t adc_value[40];
extern float    adc_average[8];
extern uint8_t  currentSendIndex;
extern const reg_w_t gDefault_config;
extern reg_w_t gDataBase;

void Uart1_Callback(void);
void Uart3_Callback(void);
void Uart1_DataDeal(void);
void Uart3_DataDeal(void);
void Uart1_Send(uint8_t* str,uint16_t len);
void Uart3_Send(uint8_t* str,uint16_t len);
void Config_Init(void);
uint16_t Get_Crc16(uint8_t *CmmBuf, uint8_t Len);

#endif